/**
 * 更新自定义顶部导航栏的高度
 */
function updateCustomBarInfo () {
  return new Promise((resolve, reject) => {
    uni.getSystemInfo({
      success: (e) => {
		//这里使用statusBarHeights防止变量冲突
        let statusBarHeights = 0
        let customBarHeight = 0
        // #ifndef MP
        statusBarHeights = e.statusBarHeight
        if (e.platform == 'android') {
          customBarHeight = e.statusBarHeight + 50
        } else {
          customBarHeight = e.statusBarHeight + 45
        };
        // #endif

        // #ifdef MP-WEIXIN
         //自定义导航栏
           const {  statusBarHeight, platform } = wx.getSystemInfoSync()
           const { top, height } = wx.getMenuButtonBoundingClientRect()
           // 状态栏高度
           //wx.setStorageSync('statusBarHeight', statusBarHeight)
		   statusBarHeights = statusBarHeight;
           // 胶囊按钮高度 一般是32 如果获取不到就使用32
           wx.setStorageSync('menuButtonHeight', height ? height : 32)
       
           // 判断胶囊按钮信息是否成功获取
           if (top && top !== 0 && height && height !== 0) {
             const navigationBarHeight = (top - statusBarHeight) * 2 + height
             // 导航栏高度
             //wx.setStorageSync('navigationBarHeight', navigationBarHeight)
			 customBarHeight = customBarHeight;
           } else {
				   //wx.setStorageSync('navigationBarHeight',platform === 'android' ? 48 : 40)
				   customBarHeight = platform === 'android' ? 48 : 40;
           }
        // #endif		

        // #ifdef MP-ALIPAY
        statusBarHeights = e.statusBarHeight
        customBarHeight = e.statusBarHeight + e.titleBarHeight
        // #endif
        resolve({
          statusBarHeights,
          customBarHeight
        })
      },
      fail: (err) => {
        console.log("获取设备信息失败", err);
        reject()
      }
    })

  })
}

export default updateCustomBarInfo
